package com.byq.mm.common.engine.listener.filter;


import org.jivesoftware.smack.packet.Message;
import org.jivesoftware.smack.packet.Stanza;

import com.byq.mm.abstractx.protocol.Defination;

import com.byq.mm.common.engine.Environment;
import com.google.gson.Gson;

public class DeviceDefinationFilter extends AbstractFilter {

	public DeviceDefinationFilter(AbstractFilter n, Environment e) {
		super(n, e);


	}

	@Override
	protected boolean filt(Stanza data) {

		Message m = (Message) data;
		String sub = m.getSubject();
		boolean isDef =  ( sub != null && sub.equals("defination"));
		return isDef;


	}

	@Override
	protected void myprocess(Stanza data) {
		String from = data.getFrom().toString().split("/")[0];
		Message m = (Message) data;
		String json = m.getBody();
		Defination def = new Gson().fromJson(json, Defination.class);
		env.getDefinationProcessor().process(def, from);
	}

}
